package ystp.controller;

import jxl.SheetSettings;
import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ystp.dao.*;
import ystp.model.*;
import ystp.service.*;
import ystp.support.JsonResult;
import ystp.support.PageInfo;
import ystp.support.StringHandle;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("fujianbjieguo")
public class FujianbJieguoController {

    public Logger log = LoggerFactory.getLogger(FujianbJieguoController.class);

    @Resource
    public YsxiangmuService ddYsxiangmuService;
    @Resource
    public YsrenyuanfenpeiService ddYsrenyuanfenpeiService;
    @Resource
    public FujianbJieguoService ddService;
    @Autowired
    YsuserService ddYsuserService;
    @Autowired
    FujianbMapper fujianbMapper;

    @RequestMapping("getjindulist")
    public JsonResult<?> getjindulist(@RequestParam("xiangmuid") String ppxiangmuId){
        try{
            List<Map<String,Object>> mmJindulist = new ArrayList<>();
            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuId);

            List<Map<String, Object>> mmUserList=ddYsrenyuanfenpeiService.findRenyuanFenpeiByXiangmuId(ppxiangmuId);
            for(Map<String, Object> ysrenyuanfenpei:mmUserList){
                Map<String, Object> mmMap = new HashMap<String, Object>();
                String mmUserId=ysrenyuanfenpei.get("userid").toString();
                Ysuser mmYsuser=ddYsuserService.findOne(mmUserId);
                String mmUserName=mmYsuser.getUsername();

                int mmPass = ddService.countPass(ppxiangmuId, mmUserId);
                int mmtotalshu = ddService.countPingui(ppxiangmuId);


                String mmShifoutijiao="";
                if("1".equals(ysrenyuanfenpei.get("issubmit").toString())){
                    mmShifoutijiao="是";
                }else {
                    mmShifoutijiao="否";
                }

                mmMap.put("username", mmUserName);
                mmMap.put("shengchanqiyeshu", mmPass+"/"+mmtotalshu);
                mmMap.put("shifoutijiao", mmShifoutijiao);
                mmJindulist.add(mmMap);

            }
            return JsonResult.getSuccessResult(mmJindulist);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("fujianjieguo/getjindulist:error",e);
            return JsonResult.getErrorResult("fujianjieguo/getjindulist:error " + e.getMessage());
        }
    }

    @RequestMapping("getResultCount")
    public JsonResult<?> getResultCount(@RequestParam("xiangmuid") String ppXiangmuId,
                                        @RequestParam("xiangmuleixing") String ppxiangmuleixing,
                                        @RequestParam("userid") String ppUserId) {
        try {

            Ysxiangmu mmYsxiangmu = ddYsxiangmuService.findOne(ppXiangmuId);
            if (mmYsxiangmu.getIsactived() != 1) {
                return JsonResult.getErrorResult("投票尚未启动");
            }
            List<Ysrenyuanfenpei> list = ddYsrenyuanfenpeiService.findbyUserIDandXiangmuId(ppUserId, ppXiangmuId);
            if (list.size() < 1) {
                return JsonResult.getErrorResult("人员-项目分配信息不存在");
            }
            int mmPass = ddService.countPass(ppXiangmuId, ppUserId);

            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("qiyepass", mmPass);
            return JsonResult.getSuccessResult(mmMap);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("fujianbjieguo/getResultCount:error", e);
            return JsonResult.getErrorResult("fujianbjieguo/getResultCount:error " + e.getMessage());
        }
    }

    @RequestMapping("vote")
    public JsonResult<?> vote(@RequestParam("pinzhongxuhao") String ppPingzhongxuhao,
                              @RequestParam("pinguixuhao") String ppPinguixuhao,
                              @RequestParam("xiangmuid") String ppxiangmuid,
                              @RequestParam("userid") String ppuserId,
                              @RequestParam("result") String ppresult) {
        try {
            Ysxiangmu mmYsxiangmu = ddYsxiangmuService.findOne(ppxiangmuid);
            if (mmYsxiangmu.getIsactived() != 1) {
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            FujianbJieguo mmjieguo = new FujianbJieguo();
            FujianbJieguo mmuserjieguo = ddService.checkexistByUserId(ppPinguixuhao, ppuserId, ppxiangmuid);

                if(ppresult.equals("1")) {
                    int gongxiaocount=ddService.checkCountYouwugongxiao(ppxiangmuid);
                    List<Map<String, Object>> mmyitoulist=ddService.findYouxiaoyitou(ppxiangmuid,ppuserId);
                    Double mm=((double)1/(double)2)*gongxiaocount;
                    int mmBiaozhu=(int)Math.ceil(mm);
                    if(mmyitoulist.size()>=mmBiaozhu){
                        return JsonResult.getErrorResult("表决失败，功效相同的勾选数量超了。");
                    }

                    if (ddService.checkCountByPinzhongandUserId(ppPingzhongxuhao, ppuserId,ppxiangmuid) < 2) {
                        if (mmuserjieguo != null) {//已经存在
                            String mmId = mmuserjieguo.getId();
                            mmjieguo.setId(mmId);
                            mmjieguo.setResult(ppresult);
                            mmjieguo.setCreatetime(new Date());
                            return ddService.modify(mmjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                    : JsonResult.getErrorResult("表决失败");
                        } else {
                            mmjieguo.setId(UUID.randomUUID().toString());
                            mmjieguo.setPinzhong(ppPingzhongxuhao);
                            mmjieguo.setPingui(ppPinguixuhao);
                            mmjieguo.setUserid(ppuserId);
                            mmjieguo.setResult(ppresult);
                            mmjieguo.setCreatetime(new Date());
                            mmjieguo.setXiangmuid(ppxiangmuid);
                            return ddService.add(mmjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                    : JsonResult.getErrorResult("表决失败");
                        }
                    } else {
                        return JsonResult.getErrorResult("同一序号的品规的勾选数量不能超过2条。");
                    }
                }else{
                    if (mmuserjieguo != null) {//已经存在
                        String mmId = mmuserjieguo.getId();
                        mmjieguo.setId(mmId);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        return ddService.modify(mmjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    } else {
                        mmjieguo.setId(UUID.randomUUID().toString());
                        mmjieguo.setPinzhong(ppPingzhongxuhao);
                        mmjieguo.setPingui(ppPinguixuhao);
                        mmjieguo.setUserid(ppuserId);
                        mmjieguo.setResult(ppresult);
                        mmjieguo.setCreatetime(new Date());
                        mmjieguo.setXiangmuid(ppxiangmuid);
                        return ddService.add(mmjieguo) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }
                }


        } catch (Exception e) {
            e.printStackTrace();
            log.error("fujianjieguo/vote:error", e);
            return JsonResult.getErrorResult("fujianjieguo/vote:error " + e.getMessage());
        }
    }

    @RequestMapping("findBiaojuelist")
    public JsonResult<?> findBiaojuelist(@RequestParam("xiangmuid") String ppxiangmuId,
                                         @RequestParam("userid")String ppuserId,
                                         @RequestParam("drugname")String ppDrugname,
                                         @RequestParam("pageindex") int ppPageIndex,
                                         @RequestParam("pagesize") int ppPageSize){
        try {
            List<Map<String,Object>> mmShengchanList = new ArrayList<>();
            List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhong(ppxiangmuId,ppDrugname,ppPageIndex,ppPageSize);

            for (int i = 0; i < mmPinzhongAll.size(); i++) {
                int mmPinzhongHebingshu = 0;
                Map<String,Object> mmMap = mmPinzhongAll.get(i);
                if (mmMap!=null){
                    String mmPinzhongOne = mmMap.get("xuhao") == null ? "" : mmMap.get("xuhao").toString();
                    List<Map<String,Object>> mmPinguilist = ddService.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne,ppuserId);

                    if (mmPinguilist.size()>0){
                        mmPinzhongHebingshu = mmPinguilist.size();
                    }else{
                        mmPinzhongHebingshu = mmPinzhongHebingshu+1;
                    }

                    mmMap.put("pinguilist",mmPinguilist);
                    mmMap.put("pinzhonghebinghang",mmPinzhongHebingshu);
                }
                mmShengchanList.add(mmMap);
            }
            Integer mmCount = ddService.getPinguiCount(ppxiangmuId,ppPageIndex,ppPageSize);
            PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);

            Map<String, Object> mmReturnMap = new HashMap<String, Object>();
            mmReturnMap.put("ShengchanList", mmShengchanList);
            mmReturnMap.put("PageInfo", mmPageInfo);
            return JsonResult.getSuccessResult(mmReturnMap);

        }catch (Exception e) {
            e.printStackTrace();
            log.error("fujianbjieguo/findBiaojuelist:error",e);
            return JsonResult.getErrorResult("fujianbjieguo/findBiaojuelist:error " + e.getMessage());
        }

    }

    @RequestMapping("tghuizongbiao")
    public void tghuizongbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuId
                           ){
        Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuId);
        List<Ysrenyuanfenpei> mmUserList=ddYsrenyuanfenpeiService.findUserByXiangmuId(ppxiangmuId);

        List<Map<String,Object>> mmPinzhongAll = ddService.findPinzhong(ppxiangmuId,"",1,9999);
        Double mm=((double)1/(double)2)*mmUserList.size();
        int mmTongguopiaoshu=(int)Math.ceil(mm);

        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle="国谈药品品种生产企业遴选投票表（四）表决结果";
            String tmptitle="国谈药品品种生产企业遴选投票表（四）汇总表";

            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            wsheet.addCell(new Label(7, 0, tmptitle, wcfFC));
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,600); //第二行高度
            wsheet.mergeCells(0, 0, 16, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0, 9); //宽度
            wsheet.setColumnView(1, 15); //宽度
            wsheet.setColumnView(2, 15); //药品名称宽度
            wsheet.setColumnView(3, 21); //分类宽度
            wsheet.setColumnView(4, 9); //规格宽度
            wsheet.setColumnView(5, 9); //单位宽度
            wsheet.setColumnView(6, 16); //医保宽度
            wsheet.setColumnView(7, 9); //宽度
            wsheet.setColumnView(8, 9); //宽度
            wsheet.setColumnView(9, 9); //宽度
            wsheet.setColumnView(10, 9); //宽度
            wsheet.setColumnView(11, 11); //宽度
            wsheet.setColumnView(12, 9); //宽度
            wsheet.setColumnView(13, 16); //宽度
            wsheet.setColumnView(14, 9); //宽度
            wsheet.setColumnView(15, 9); //宽度
            wsheet.setColumnView(16, 9); //宽度
            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);
            // 不需要边框和居中的样式
            WritableFont wfont2 = new WritableFont(WritableFont.ARIAL, 8,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 垂直居中
            wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setWrap(true);


            wsheet.addCell(new Label(10, 1, "日期:"+StringHandle.shorttiemString(),wcfFC2));
            wsheet.mergeCells(10, 1, 16, 1);

            wsheet.addCell(new Label(0, 2, "序号", wcfFC));
            wsheet.addCell(new Label(1, 2, "产品编码", wcfFC));
            wsheet.addCell(new Label(2, 2, "药品名称", wcfFC));
            wsheet.addCell(new Label(3, 2, "", wcfFC));
            wsheet.addCell(new Label(4, 2, "规格", wcfFC));
            wsheet.addCell(new Label(5, 2, "单位", wcfFC));
            wsheet.addCell(new Label(6, 2, "剂型", wcfFC));
            wsheet.addCell(new Label(7, 2, "生产企业", wcfFC));
            wsheet.addCell(new Label(8, 2, "价格（元）", wcfFC));
            wsheet.addCell(new Label(9, 2, "医保", wcfFC));
            wsheet.addCell(new Label(10, 2, "是否为新增品种", wcfFC));
            wsheet.addCell(new Label(11, 2, "有无临床需求", wcfFC));
            wsheet.addCell(new Label(12, 2, "申请科室", wcfFC));
            wsheet.addCell(new Label(13, 2, "有无同功效品种", wcfFC));
            wsheet.addCell(new Label(14, 2, "预选会意见", wcfFC));
            wsheet.addCell(new Label(15, 2, "备注", wcfFC));
            /*wsheet.addCell(new Label(16, 2, "委员表决票数",wcfFC));
            wsheet.addCell(new Label(17, 2, "表决结果",wcfFC));*/




            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);


            int count = mmPinzhongAll.size();
            int mmpinzhongKaishihang = 3;
            int mmpinpaiKaishihang = 3;
            int mmpinpaiKaishihang1 = 3;


            for (int i = 0; i < count; i++) {
                Map<String, Object> mmPinzhongMap = mmPinzhongAll.get(i);

                String mmPinzhongOne = mmPinzhongMap.get("xuhao") == null ? "" : mmPinzhongMap.get("xuhao").toString();
                int mmPinzhongHebingshu = 0;

                List<Map<String, Object>> mmPingui=ddService.findPinguiFenlei(ppxiangmuId,mmPinzhongOne);
                List<Map<String, Object>> mmList = new ArrayList<>();
                for(int k = 0; k < mmPingui.size(); k++){
                    Map<String, Object> mmPinguiMap = mmPingui.get(k);
                    if(mmPinguiMap != null){
                        String pinguione = mmPinguiMap.get("beuzhu1") == null ? "" : mmPinguiMap.get("beuzhu1").toString();
                        int pinguipiaoshu=ddService.piaoshu(mmPinzhongOne,pinguione,ppxiangmuId);
                        mmPinguiMap.put("piaoshu",pinguipiaoshu);
                        if(pinguipiaoshu>=mmTongguopiaoshu){
                            mmList.add(mmPinguiMap);
                        }
                    }
                }

                for(int a = 0; a < mmList.size(); a++){
                    String pingui= mmList.get(a).get("beuzhu1").toString();
                    List<Map<String, Object>> mmshengchanlist = fujianbMapper.findShengchanqiye(ppxiangmuId,pingui);
                    mmPinzhongHebingshu+=mmshengchanlist.size();
                }
                mmPinzhongHebingshu=mmPinzhongHebingshu-1;
                int mmHebingshu = 0;
                for(int a = 0; a < mmList.size(); a++){

                    String pingui= mmList.get(a).get("beuzhu1").toString();
                    String piaoshu= mmList.get(a).get("piaoshu").toString();
                    /*String guige= mmList.get(a).get("guige").toString();*/


                    List<Map<String, Object>> mmshengchanlist = fujianbMapper.findShengchanqiye(ppxiangmuId,pingui);
                    if (mmshengchanlist.size()>0){
                        mmHebingshu = mmshengchanlist.size()-1;
                    }
                    for (Map<String, Object> mmMap : mmshengchanlist) {

                            String chanpinbianma = mmMap.get("chanpinbianma") == null ? "" : mmMap.get("chanpinbianma").toString();
                            String yaopinmingcheng = mmMap.get("yaopinmingcheng") == null ? "" : mmMap.get("yaopinmingcheng").toString();
                            String guige = mmMap.get("guige") == null ? "" : mmMap.get("guige").toString();
                            String danwei = mmMap.get("danwei") == null ? "" : mmMap.get("danwei").toString();
                            String jixing = mmMap.get("jixing") == null ? "" : mmMap.get("jixing").toString();
                            String shengchanqiye = mmMap.get("shengchanqiye") == null ? "" : mmMap.get("shengchanqiye").toString();
                            String jiage = mmMap.get("jiage") == null ? "" : mmMap.get("jiage").toString();
                            String yibao = mmMap.get("yibao") == null ? "" : mmMap.get("yibao").toString();
                            String shifouxinzengpinzhong = mmMap.get("shifouxinzengpinzhong") == null ? "" : mmMap.get("shifouxinzengpinzhong").toString();
                            String youwulinchuangxuqiu = mmMap.get("youwulinchuangxuqiu") == null ? "" : mmMap.get("youwulinchuangxuqiu").toString();
                            String youwutonggongxiao = mmMap.get("youwutonggongxiao") == null ? "" : mmMap.get("youwutonggongxiao").toString();
                            String xieyixiaoqi = mmMap.get("xieyixiaoqi") == null ? "" : mmMap.get("xieyixiaoqi").toString();
                            String yuxuanhuiyijian = mmMap.get("yuxuanhuiyijian") == null ? "" : mmMap.get("yuxuanhuiyijian").toString();
                            String shenqingkeshi = mmMap.get("shenqingkeshi") == null ? "" : mmMap.get("shenqingkeshi").toString();
                            String beizhu = mmMap.get("beizhu") == null ? "" : mmMap.get("beizhu").toString();

                            wsheet.setRowView(mmpinpaiKaishihang,700);
                            wsheet.addCell(new Label(1, mmpinpaiKaishihang, chanpinbianma, wcfFC));
                            wsheet.addCell(new Label(2, mmpinpaiKaishihang, yaopinmingcheng, wcfFC));
                            /*wsheet.addCell(new Label(3, mmpinpaiKaishihang, guige, wcfFC));*/
                            wsheet.addCell(new Label(4, mmpinpaiKaishihang, guige, wcfFC));
                            wsheet.addCell(new Label(5, mmpinpaiKaishihang, danwei, wcfFC));
                            wsheet.addCell(new Label(6, mmpinpaiKaishihang, jixing, wcfFC));
                            wsheet.addCell(new Label(7, mmpinpaiKaishihang, shengchanqiye, wcfFC));
                            wsheet.addCell(new Label(8, mmpinpaiKaishihang, jiage, wcfFC));
                            wsheet.addCell(new Label(9, mmpinpaiKaishihang, yibao, wcfFC));
                            wsheet.addCell(new Label(10, mmpinpaiKaishihang, shifouxinzengpinzhong, wcfFC));
                            wsheet.addCell(new Label(11, mmpinpaiKaishihang, youwulinchuangxuqiu, wcfFC));
                            wsheet.addCell(new Label(12, mmpinpaiKaishihang, shenqingkeshi, wcfFC));
                            wsheet.addCell(new Label(13, mmpinpaiKaishihang, youwutonggongxiao, wcfFC));
                            wsheet.addCell(new Label(14, mmpinpaiKaishihang, yuxuanhuiyijian, wcfFC));
                            wsheet.addCell(new Label(15, mmpinpaiKaishihang, beizhu, wcfFC));
                            mmpinpaiKaishihang = mmpinpaiKaishihang + 1;
                    }
                    wsheet.addCell(new Label(3, mmpinpaiKaishihang1, pingui, wcfFC));
                    wsheet.mergeCells(3, mmpinpaiKaishihang1, 3, mmpinpaiKaishihang1+mmHebingshu);
                    wsheet.addCell(new Label(16, mmpinpaiKaishihang1, piaoshu, wcfFC));
                    wsheet.mergeCells(16, mmpinpaiKaishihang1, 16, mmpinpaiKaishihang1+mmHebingshu);
                   /* wsheet.addCell(new Label(4, mmpinpaiKaishihang1, guige, wcfFC));
                    wsheet.mergeCells(4, mmpinpaiKaishihang1, 4, mmpinpaiKaishihang1+mmHebingshu);*/
                    mmpinpaiKaishihang1 = mmpinpaiKaishihang1 + mmHebingshu + 1;
                }
                wsheet.addCell(new Label(0, mmpinzhongKaishihang, mmPinzhongOne, wcfFC));
                wsheet.mergeCells(0, mmpinzhongKaishihang, 0, mmpinzhongKaishihang + mmPinzhongHebingshu);
                mmpinzhongKaishihang = mmpinzhongKaishihang + mmPinzhongHebingshu + 1;

            }
            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }




}